﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
using WPCordovaClassLib.Cordova.JSON;

namespace Cordova.Extension.Commands
{

    public class WPNative : BaseCommand
    {
        public void GetIpAddress(string args)
        {
            //IpAddressParameters ipParam = JsonHelper.Deserialize<string[]>(args);
            var wifiIP = "";
            
            try
            {
                var interfaces = Windows.Networking.Connectivity.NetworkInformation.GetHostNames();
                foreach (var item in interfaces)
                {
                    if (item.IPInformation.NetworkAdapter.IanaInterfaceType == 71)
                        wifiIP = item.RawName;
                }
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, wifiIP));
            }
            catch(Exception){
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ""));
            }
        }

        public async void LaunchWiFi(string args)
        {
            try
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-wifi:"));

                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, true));
            }
            catch (Exception)
            {
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, false));
            }
        }

    }
}
